<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>

    <style>
        /* 常规reset动作 */
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }

        ul,
        ol,
        li {
            list-style-type: none;
        }

        #box {
            width: 800px;
            height: 600px;
            border: 1px solid black;
            margin: 50px auto;

            display: flex;
            flex-direction: column;
        }

        #box>ul {
            width: 100%;
            height: 60px;
            /* background-color: coral; */
            display: flex;
        }

        #box>ul>li {
            /* width: 100%; */
            flex-grow: 1;
            height: 100%;
            background-color: orange;
            display: flex;
            justify-content: center;
            align-items: center;
            color: white;
            font-size: 20px;
        }

        #box>ul>li.active {
            background-color: darkorange;
        }

        #box>ol {
            width: 100%;
            /* height: 50px; */
            flex-grow: 1;
            background-color: burlywood;
            position: relative;
        }

        #box>ol>li {
            width: 100%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
            display: none;
            justify-content: center;
            align-items: center;
            color: white;
            font-size: 50px;
        }

        #box>ol>li.active {
            display: flex;
        }
    </style>

</head>

<body>
    <div id="box">
        <ul id="ulTabs">
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ul>
        <ol id="olContents">
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ol>
    </div>

    <script>
        // 找出所有标签
        var tabs = document.querySelectorAll("ul>li")

        // 找出所有内容
        var contents = document.querySelectorAll("ol>li")

        tabs.forEach(

            // 对每个标签加点击事件
            function(tab,index){
                tab.onclick = function(){

                    // 所有标签取消active
                    tabs.forEach(
                        function(t){
                            t.classList.remove("active")
                        }
                    )

                    // 点击的标签自己添加active样式
                    this.classList.add("active")

                    /* 将相同序号的ol>li切换为active 而其它ol>li取消active */
                    contents.forEach(
                        function(con){
                            con.classList.remove("active")
                        }
                    )

                    // 将序号相同的content追加active样式
                    contents[index].classList.add("active")
                }
            }

        )
    </script>

</body>

</html>